package com.lu.statistics.fileService.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lu.statistics.entity.SysFile;
import com.lu.statistics.fileService.FileService;
import com.lu.statistics.fileService.FileUploadService;
import com.lu.statistics.mapper.SysFileMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;

@Service
public class FileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> implements FileService {
    @Autowired
    private SysFileMapper fileMapper;
    @Autowired
    private FileUploadService fileUploadService;

    @Override
    public boolean deleteFile(String fileFullPath) {
        //查看文件路径
        String filePathPrefix = fileUploadService.getFileSavePath();
        //解决文件绝对路径
        String path = filePathPrefix + fileFullPath;
        File file = new File(path);
        boolean delete = file.delete();
        if (delete == true) {
            fileMapper.deleteFileByFileFullPath(fileFullPath);
            return true;
        }
        return false;

    }
}
